package com.customization.assets.util;

import com.customization.commons.Console;
import com.customization.commons.LogTool;
import weaver.interfaces.schedule.BaseCronJob;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractCronJob extends BaseCronJob {

    private List<String> currTasks = new ArrayList<String>();	// true 表示正在执行上一轮任
    private LogTool log = new LogTool("/log/assetlog/huangwm/AbstractCronJob",false);
    @Override
    public void execute() {
        if (currTasks.contains(this.getClass().getName())) {
            log.writeLog("上一轮计划任务未结束=>>>"+this.getClass().getName());
            return ;
        }

        long time = System.currentTimeMillis();
        try {
            log.writeLog("计划任务开始=>>>"+this.getClass().getName());
            currTasks.add(this.getClass().getName());
            start();
        } catch (Exception e) {
            log.writeLog("计划任务异常 "+e.getMessage());
            e.printStackTrace();
        } finally {
            currTasks.remove(this.getClass().getName());
            time = System.currentTimeMillis() - time;
            log.writeLog("总耗时（秒）：" + (time / 1000));
            log.writeLog("计划任务结束。");
        }

    }

    public abstract void start() throws Exception;
}
